#include <iostream>
#include <cmath>

int x[100];

int Place(int k)
{
    for (int i = 1; i < k; i++)
    {
        if (x[i] == x[k] || std::abs(i - k) == std::abs(x[i] - x[k]))
        {
            return false;
        }
    }
    return true;
}
int Queen(int n)
{

    // n 为皇后的个数
    int count = 0;
    // 用于记录 n 皇后方案的个数
    for (int i = 1; i <= n; i++)
    {
        x[i] = 0;
        int k = 1;
        while (k >= 1)
        {
            x[k] = x[k] + 1;
            while (x[k] <= n && (!Place(k)))
            {
                x[k] = x[k] + 1;
            }
            if (k == n && x[k] <= n)
            {
                count++;
                for (int i = 1; i <= k; i++)
                {
                    std::cout << x[i] << " ";
                }
                std::cout << std::endl;
            }
            else if (k < n && x[k] <= n)
            {
                k = k + 1;
            }
            else
            {
                x[k] = 0;
                k = k - 1;
            }
        }
        return count;
    }
}

int main()
{
    std::cout << "请输入皇后的数量: ";
    int n;
    std::cin >> n;
    int re = Queen(n);
    std::cout << "n皇后问题的解的个数为: " << re << std::endl;
    return 0;
}